package org.dromara.business.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.business.domain.vo.AuditVo;
import org.dromara.business.domain.bo.AuditBo;
import org.dromara.business.service.AuditService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 提现审核
 *
 * @author zlj
 * @date 2024-08-22
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/business/audit")
public class AuditController extends BaseController {

    private final AuditService auditService;

    /**
     * 查询提现审核列表
     */
//    @SaCheckPermission("business:audit:list")
    @GetMapping("/list")
    public TableDataInfo<AuditVo> list(AuditBo bo, PageQuery pageQuery) {
        return auditService.queryPageList(bo, pageQuery);
    }

    /**
     * 查询提现商家审核列表
     */
    @GetMapping("/myList")
    public TableDataInfo<AuditVo> myList(PageQuery pageQuery) {
        return auditService.myList(pageQuery);
    }

    /**
     * 导出提现审核列表
     */
    @SaCheckPermission("business:audit:export")
    @Log(title = "提现审核", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(AuditBo bo, HttpServletResponse response) {
        List<AuditVo> list = auditService.queryList(bo);
        ExcelUtil.exportExcel(list, "提现审核", AuditVo.class, response);
    }

    /**
     * 获取提现审核详细信息
     *
     * @param auditId 主键
     */
    @SaCheckPermission("business:audit:query")
    @GetMapping("/{auditId}")
    public R<AuditVo> getInfo(@NotNull(message = "主键不能为空")
                              @PathVariable Long auditId) {
        return R.ok(auditService.queryById(auditId));
    }

    /**
     * 新增提现审核
     */
//    @SaCheckPermission("business:audit:add")
//    @Log(title = "提现审核", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody AuditBo bo) {
        return toAjax(auditService.insertByBo(bo));
    }

    /**
     * 修改提现审核
     */
    @SaCheckPermission("business:audit:edit")
    @Log(title = "提现审核", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody AuditBo bo) {
        return toAjax(auditService.updateByBo(bo));
    }

    /**
     * 删除提现审核
     *
     * @param auditIds 主键串
     */
    @SaCheckPermission("business:audit:remove")
    @Log(title = "提现审核", businessType = BusinessType.DELETE)
    @DeleteMapping("/{auditIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] auditIds) {
        return toAjax(auditService.deleteWithValidByIds(List.of(auditIds), true));
    }
}
